#include <stdio.h>
#include <stdbool.h>
int main()
{
    //在arr数组中找n的值 有就打印arr的下标 没有就打印找不到
    int arr[] = {1,2,3,4,5,6,7,8,9,10};//字符串后面才有/0
    int n = 7;
    int left = 0;
    int right = sizeof (arr) / sizeof (arr[0]) - 1;//字符串后面才有/0
    bool found = false;//假设没找到
    while (left <= right)
    {
        int mid = (left + right) / 2;
        if (arr[mid] < n)
        {
            left = mid + 1;
        }
        else if (arr[mid] > n)
        {
            right = mid - 1;
        }
        else
        {
            printf("%d\n", mid);
            found = true;
            break;//找到了就跳出循环
        }
        
    }
    if (!found)
    {
        printf("找不到\n");
    }

    return 0;
}